﻿using System.ComponentModel;

namespace Barrage.Controls
{
    public class ListViewEx : ListView
    {
        [DefaultValue(false)]
        [Category("ExtendedAttribute")]
        [Description("是否自动清空列表")]
        public bool IsClearItems { get; set; } = false;


        [DefaultValue(500)]
        [Category("ExtendedAttribute")]
        [Description("超过多少行后开始清空列表")]
        public int ClearItemsSize { get; set; } = 500;


        public ListViewEx()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer, value: true);
            UpdateStyles();
            base.GridLines = true;
            base.View = View.Details;
            base.FullRowSelect = true;
            DoubleBuffered = true;
        }

        public void ClearItems()
        {
            if (IsClearItems && base.Items.Count >= ClearItemsSize)
            {
                base.Items.Clear();
            }
        }
    }
}
